home *** CD-ROM | disk | FTP | other *** search
- Path: news.db.erau.edu!kochank
- From: kochank@news.db.erau.edu (Konrad Kochan)
- Newsgroups: comp.lang.c++
- Subject: Help with a program PLS! :)
- Date: 1 Mar 1996 03:29:32 GMT
- Organization: Embry-Riddle Aeronautical University
- Message-ID: <4h5qut$5fp@deadbird.db.erau.edu>
- NNTP-Posting-Host: 155.31.1.1
- NNTP-Posting-User: kochank
- X-Newsreader: TIN [version 1.2 PL2]
-
- I need help with this program:
-
- Reads strings from file WORDS.IN, words in string are lower/upper caps
- sentences seperated by commas and periods (ie: Marry, had a little, lamb. DOH)
-
- It has to sort the array and print it to file WORDS.OUT..
-
- Ok, I got it ALMOST working.. it sorts everything accept that it puts
- CAPS words b4 lower case (Dupa before death, etc etc..)
-
- Here is the code: (I hope)
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- /******* Function Declarations ********/
- char dataArr[][26];
- int index = 0;
-
- /******** Main function of the program *********/
-
- main()
- {
- int i;
- FILE * fin, * fout;
- if (!(fin = fopen("WORDS.IN", "r")))
- {
- printf("Something is wrong: Probably file missing.\n");
- exit(1); /* Program exits here if file is missing. */
- }
- printf("Input File = WORDS.IN\n");
-
- /* The next function scans the file for all the strings, removes periods
- and commas, and passes the "clean" string to dataArr
- */
-
- while ((fscanf(fin, "%s", & dataArr[index])) !=EOF)
- {
- strtok(dataArr[index], ",.");
- strtok(NULL, ",.");
- index++;
- }
- close(fin);
-
- /* Prints the original array, dataArr */
-
- for (i=0; i<index; i++)
- printf("Original array: %s \n", dataArr[i]);
-
- /* Sorts the array, dataArr */
-
- qsort(dataArr, index, 26*sizeof(char), strcmp);
-
- if (!(fout = fopen("WORDS.OUT", "w")))
- {
- printf("Something is wrong: File might be write protected.\n");
- exit(1); /* Program exits here if file can't be opened. */
- }
-
- /* Prints the sorted array to the screen */
-
- for (i=0; i<index; i++) {
- printf("\tSorted array: %s\n", dataArr[i]);
-
- /* Writes the array to the file, WORDS.OUT */
-
- fprintf(fout, "%s\n", & dataArr[i]);
- }
- if (fclose(fout) == EOF)
- {
- printf("Something is wrong: File probably write protected.\n");
- exit(1);
- }
-
- }
-
- If you can help me fix this thing I will appreciate it! ..
-
- Konrad
-
-